package cn.highset.modules.base.serviceimpl.mybatis;

import cn.highset.common.constant.CommonConstant;
import cn.highset.modules.base.dao.mapper.ProvinceMapper;
import cn.highset.modules.base.entity.Province;
import cn.highset.modules.base.service.mybatis.IProvinceService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Victor
 */
@Service
public class IProvinceServiceImpl extends ServiceImpl<ProvinceMapper, Province> implements IProvinceService {

    /**
     * 获取集合
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> provinceList() {
        return baseMapper.list();
    }

    /**
     * 通过id获取  名称
     *
     * @param provinceId
     * @return
     */
    @Override
    public String getLabelById(String provinceId) {
        Province province = baseMapper.selectById(provinceId);
        return province == null ? "" : province.getLabel();
    }

    /**
     * 通过id获取  名称
     *
     * @param label
     * @return
     */
    @Override
    public String getIdByLabel(String label) {
        if (StrUtil.isBlank(label)) {
            return "";
        }
        List<Province> list = baseMapper.selectList(new QueryWrapper<Province>().eq("label", label).eq("del_flag", CommonConstant.STATUS_NORMAL));
        if (list != null && list.size() > 0) {
            return list.get(0).getId();
        }
        return "";
    }
}
